import uvicorn
from fastapi import FastAPI

from app.core.database import register_tortoise_orm
from app.events.register_center import lifespan
from app.core.config import get_settings
from app.exception_handlers.handler_center import register_exception_handlers
from app.router.router_center import core_router

core_app = FastAPI(title="FastAPI Demo", version="1.0.0", lifespan=lifespan)

# orm 和 exception 注册 放在lifespan中 有问题
# 注册tortoise orm
register_tortoise_orm(core_app)
# 注册异常处理
register_exception_handlers(core_app)
core_app.include_router(core_router, prefix="/api")

if __name__ == "__main__":
    setting = get_settings()
    uvicorn.run(
        "main:core_app",
        host=setting.server.host,
        port=setting.server.port,
        reload=True,
    )
